﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace P2PTransmit.ViewModal.Command
{
    public class FileDrop
    {
        static int Seed;
        static FileDrop()
        {
            var rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
            var arr = new byte[4];
            rng.GetBytes( arr );
            Seed = BitConverter.ToInt32( arr, 0 );
        }
        static string RandHash()
        {
            string s = "1234567890qwertyuiopasdfghjklzxcvbnm-=/*-+.";
            var sb = new StringBuilder();
            var rand = new Random( Seed );
            for(int i=0;i<20;i++ )
            {
                sb.Append( s[rand.Next( 0, s.Length - 1 )] );
            }
            return sb.ToString();
        }

        AsyncObservableCollection<Modal.NetworkTask> Task;
        public FileDrop(AsyncObservableCollection<Modal.NetworkTask> collection)=>Task=collection;

        public void Create(object files)
        {
            var task = new Modal.NetworkTask( files, Task.Count );
            task.CurrentFileIndex = 0;
            task.CurrentFileLength = task.Files[0].FileLength;
            task.CurrentFileName = task.Files[0].FileName;
            task.TaskName = task.CurrentFileName;
            task.CurrentPosition = 0;
            task.Hash = RandHash();
            Task.Add(task);
        }
    }
}
